<?php
namespace App\Http\Controllers\Admin\Report;

use App\Http\Controllers\Admin\Report\Service\Report;
use App\Http\Controllers\Admin\Scene\Service\Spot;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

/**
 * Created by PhpStorm.
 * User: wanghaibo
 * Date: 17/12/11
 * Time: 10:43
 */
class ReportController extends Controller
{
    private $routePrefix = 'admin.report';
    private $manager;
    public function sale(Request $request){
        //
        if($request->ajax()){
            $do = isset($request->do)?$request->do:'list';
            switch ($do){
                case 'list':
                    $return  = $this->saleList($request);
                    break;
                default:
                    $return  = $this->saleList($request);
                    break;
            }
            return $return;
        }else{
            return view('admin.report.sale',[
                'routePrefix'   =>  $this->routePrefix
            ]);
        }
    }
    private function saleList(Request $request){
        $this->manager = new Report(1);
        $return =  $this->manager->getReport($request);
        return $return;
    }
    public function distribute(Request $request){

        if($request->ajax()){
            $do = isset($request->do)?$request->do:'list';
            switch ($do){
                case 'list':
                    $return  = $this->distributeList($request);
                    break;
                default:
                    $return  = $this->distributeList($request);
                    break;
            }
            return $return;
        }else{
            return view('admin.report.distribute',[
                'routePrefix'   =>  $this->routePrefix
            ]);
        }
    }
    private function distributeList(Request $request){
        $this->manager = new Report(2);
        $return =  $this->manager->getReport($request);
        return $return;
    }

    public function spot(Request $request){
        if($request->ajax()){
            $do = isset($request->do)?$request->do:'list';
            switch ($do){
                case 'list':
                    $return  = $this->spotList($request);
                    break;
                default:
                    $return  = $this->spotList($request);
                    break;
            }
            return $return;
        }else{
            return view('admin.report.spot',[
                'routePrefix'   =>  $this->routePrefix,
                'spots' =>  Spot::getSelectList()
            ]);
        }
    }
    private function spotList(Request $request){
        $this->manager = new Report(3);
        $options = [];
        if(isset($request->scene_id)&&$request->scene_id){
            $options = [
                'where' =>  [
                    'scenic'    =>  $request->scene_id
                ]
            ];
        }
        $return =  $this->manager->getReport($request,$options);
        return $return;
    }
}